﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Entity;
using DataAccess;

namespace StudentAttendanceChecking
{
    public partial class frmMain : Form
    {
        Account acc = new Account();
        BranchClassTree bcTree = new BranchClassTree();

        public frmMain()
        {
            InitializeComponent();
            this.WindowState = FormWindowState.Maximized;
        }

        private void tolNewStudent_Click(object sender, EventArgs e)
        {
            Form currentForm = this.ActiveMdiChild;
            frmListStudent fNewStudent = new frmListStudent(acc);
            fNewStudent.MdiParent = this;
            fNewStudent.WindowState = FormWindowState.Maximized;
            if (currentForm == null)
            {
                fNewStudent.Show();
            }
        }
        //load tree
        private void LoadTree()
        {
            tvList.Nodes.Add(bcTree.getBranchClass(acc));
            tvList.ExpandAll();
        }
        //load tabs
        private void LoadIconTabs()
        {
            tabControl.TabPages[0].ImageIndex = 0;
            tabControl.TabPages[1].ImageIndex = 1;
        }
        //load icon titClose
        private void LoadIconClose()
        {
            picClose.BackgroundImage = (Image)imgTitle.Images[0];
        }
        private void frmMain_Load(object sender, EventArgs e)
        {
            //tao doi tuong dang nhap 
            acc.accountID = 1;
            acc.name = "Nguyen Tuan";
            //load du lieu
            LoadIconTabs();
            LoadIconClose();
            timDateTime.Enabled = true;
            //load tree
            LoadTree();
            //load student
            frmListStudent fNewStudent = new frmListStudent(acc);
            fNewStudent.MdiParent = this;
            fNewStudent.WindowState = FormWindowState.Maximized;
            fNewStudent.Show();
        }

        private void tabControl_Selected(object sender, TabControlEventArgs e)
        {
            if (e.TabPageIndex == 0)
            {
                lblTitle.Text = "Explorer";
            }
            else
            {
                lblTitle.Text = "Students";
            }
        }

        private void picClose_Click(object sender, EventArgs e)
        {
            if (panelLeft.Width > 25)
            {
                panelLeft.Width = 25;
                tabControl.Width = 25;
                picClose.Left = 5;
                lblTitle.Visible = false;
                picClose.BackgroundImage = (Image)imgTitle.Images[1];
            }
            else if(panelLeft.Width<=25)
            {
                panelLeft.Width = 280;
                tabControl.Width = 280;
                tabControl.TabPages[0].Width = 280;
                tabControl.TabPages[1].Width = 280;
                picClose.Left = 241;
                lblTitle.Visible = true;
                picClose.BackgroundImage = (Image)imgTitle.Images[0];
            }
        }

        private void timDateTime_Tick(object sender, EventArgs e)
        {
            tolblDateTime.Text = DateTime.Now.ToString();
        }

        private void tolFind_Click(object sender, EventArgs e)
        {
            MessageBox.Show(frmListStudent.id.ToString());
        }

    }
}
